home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / util / sys / 68040Lib.lha / 68040Lib / Install / ScanToConfig.rexx < prev    next >
OS/2 REXX Batch file  |  2000-04-13  |  14KB  |  375 lines

  1. /*********************************************************
  2.  ** ScanToConfig                                          **
  3.  **                                                     **
  4.  ** Builds the MMU-Configuration file automatically     **
  5.  ** from the MuScan output, including kludges for      **
  6.  ** bad or mis-designed hardware                        **
  7.  ** Version 1.04 © 2000 THOR-Software, Thomas Richter   **
  8.  ** 13.04.2000                                          **
  9.  *********************************************************/
  10.  
  11. PARSE ARG destination p5disable .
  12.  
  13.         if (destination = '') then
  14.                 destination = '*'
  15.  
  16.     p5 = 1;
  17.     if (upper(p5disable) = 'NOP5') then
  18.         p5 = 0;
  19.         
  20.         rec = 25;
  21.  
  22.         if (OPEN(.out,destination,'W')) THEN; DO
  23.                 rv=WRITELN(.out,";*************************************************************************");
  24.                 rv=WRITELN(.out,";** MMU Configuration file                                              **");
  25.                 rv=WRITELN(.out,";**                                                                     **");
  26.                 rv=WRITELN(.out,";** this file is read on startup by the mmu.library and used to modify  **");
  27.                 rv=WRITELN(.out,";** the pre-calculated or scanned MMU table                             **");
  28.                 rv=WRITELN(.out,";**                                                                     **");
  29.                 rv=WRITELN(.out,";** © 1999,2000 THOR Software, Thomas Richter                           **");
  30.                 rv=WRITELN(.out,";*************************************************************************");
  31.                 rv=WRITELN(.out,"");
  32.                 rv=WRITELN(.out,"");
  33.                 rv=WRITELN(.out,"");
  34.                 rv=WRITELN(.out,"; the current version of the MMU library knows four commands that can");
  35.                 rv=WRITELN(.out,"; be used in this file:");
  36.                 rv=WRITELN(.out,"; CLEARTTX clears all or parts of the transparent translation registers");
  37.                 rv=WRITELN(.out,"; ADDMEM   adds memory to the exec free list pool. BE WARNED, this command");
  38.                 rv=WRITELN(.out,";          does NOT modify the MMU tables, this must be done manually with");
  39.                 rv=WRITELN(.out,";          SETCACHEMODE");
  40.                 rv=WRITELN(.out,"; SETCACHEMODE  defines the MMU tables.");
  41.                 rv=WRITELN(.out,"; DESCRIPTORCACHEINHIBIT defines whether the data cache should be disabled");
  42.                 rv=WRITELN(.out,"; for the MMU descriptors. It's usually OFF meaning the cache will remain");
  43.                 rv=WRITELN(.out,"; enabled. This is fine for the mmu.library, but certain hacks might require");
  44.                 rv=WRITELN(.out,"; an ON argument here. Note that this means more work for the library.");
  45.                 rv=WRITELN(.out,"");
  46.                 rv=WRITELN(.out,"");
  47.                 rv=WRITELN(.out,"ClearTTx        ;ignore all TTX registers if any. We don't need them");
  48.                 rv=WRITELN(.out,"");
  49.                 rv=WRITELN(.out,";DescriptorCacheInhibit ON     ;make access to MMU descriptors cache inhibited");              
  50.                 rv=WRITELN(.out,"");
  51.                 rv=WRITELN(.out,"");
  52.                 rv=WRITELN(.out,";Board specific setup follows here,");
  53.                 rv=WRITELN(.out,";generated by ScanToConfig 1.04 © 14.04.2000 THOR-Software");
  54.                 rv=WRITELN(.out,"");
  55.  
  56.         rv=WRITELN(.out,";General memory setup follows.");
  57.         rv=WRITELN(.out,";The following lines are a compatibility kludge for some P5 boards");
  58.         rv=WRITELN(.out,";which enable the MMU prior to the 68040/68060 library and leave");
  59.         rv=WRITELN(.out,";the memory in CACHEINHIBIT state. You may remove the following");
  60.         rv=WRITELN(.out,";lines on all other machines most likely.");
  61.         rv=WRITELN(.out,"");
  62.  
  63.         ADDRESS COMMAND "MemModes >T:MemInfo";
  64.         IF (OPEN(.meminfo,"T:MemInfo",'R')) THEN; DO 
  65.             DO UNTIL EOF(.meminfo)
  66.                 line = READLN(.meminfo);
  67.                 WRITELN(.out,line);
  68.             END;
  69.             rv=CLOSE(.meminfo);
  70.         END;
  71.         
  72.         rv=WRITELN(.out,";Memory setup end.");
  73.         rv=WRITELN(.out,"");
  74.         rv=WRITELN(.out,"");
  75.  
  76.         ADDRESS COMMAND 'FindPort "BOOT-MMU-Port"'
  77.         portmode = RC;
  78.  
  79.         ADDRESS COMMAND "ShowBoards to T:BoardInfo";
  80.         boards = 0;
  81.         if (OPEN(.boardinfo,"T:BoardInfo",'R')) then; do
  82.             DO UNTIL EOF(.boardinfo)
  83.                 line = READLN(.boardinfo)
  84.                 IF line ~= '' THEN; DO
  85.                     PARSE VAR line 'Type:' type 'Product:' product 'Manufacturer:' mf 'Serial#:' id 'BoardAddr:' from 'BoardSize:' size;
  86.                     boards = boards + 1;
  87.                     type.boards=X2D(type);
  88.                     product.boards=X2D(product);
  89.                     mf.boards=X2D(mf);
  90.                     id.boards=X2D(id);
  91.                     base.boards=X2D(SUBSTR(from,2,6));
  92.                     end.boards=X2D(SUBSTR(size,2,6))+base.boards;
  93.                 END
  94.             END    
  95.             rv=CLOSE(.boardinfo);
  96.         END
  97.         ADDRESS COMMAND "MuScan to T:BoardInfo";
  98.                 if (OPEN(.boardinfo,"T:BoardInfo",'R')) then; do
  99.                         rec = 0;
  100.             scan = 0;
  101.             portwarn = 0;
  102.             ppcwarn = 0;
  103.                         DO UNTIL EOF(.boardinfo)
  104.                                 line = READLN(.boardinfo)
  105.                 IF scan = 0 THEN; DO
  106.                     IF line = 'Memory map:' THEN; DO
  107.                         scan = 1;
  108.                     END;
  109.                 END; ELSE; DO
  110.                     IF line ~= '' THEN; DO
  111.                         base = SUBWORD(line,1,1);
  112.                         end  = SUBWORD(line,3,1);
  113.                         mode = SUBWORD(line,4);
  114.                         rv   = ScanEntry(base,end,mode);    
  115.                     END;
  116.                 END
  117.             END
  118.                         rv=CLOSE(.boardinfo);
  119.                 END
  120.  
  121.         /* P5 setup kludges follow here..... Sigh */
  122.  
  123.         romlibs        = 0;            /* libs in ROM? */
  124.  
  125.         IF p5 THEN; DO
  126.             ADDRESS COMMAND 'P5Identify'
  127.             p5mode         = RC;            /* Possibly P5 board? */
  128.             ADDRESS COMMAND 'FindPort "BOOT-MMU-Port"'
  129.             portmode     = RC;            /* MMU setup kludge? */
  130.             ADDRESS COMMAND 'FindResident "ppc.library"'
  131.             ppclibmode     = RC;            /* PPCLib in ROM? */
  132.             ADDRESS COMMAND 'FindResident "68060quick.library"'
  133.             quicklibmode     = RC;            /* quick lib in ROM? */
  134.             ADDRESS COMMAND 'FindResident "68060.library"'
  135.             libmode     = RC;            /* 060 lib in ROM? */
  136.             ADDRESS COMMAND 'FindResident "68040.library"'
  137.             lib4mode     = RC;            /* 040 lib in ROM? */
  138.  
  139.             IF p5mode ~= 0 THEN; DO
  140.                 p5init         = 1
  141.                 ppccheck    = 1
  142.             END;
  143.         
  144.             IF ppclibmode = 0 THEN; DO
  145.                 ppccheck    = 1
  146.             END;
  147.  
  148.             IF portmode = 0 THEN; DO
  149.                 ppccheck     = 1
  150.                 p5init         = 1
  151.             END;
  152.  
  153.             IF (quicklibmode = 0) | (libmode = 0) | (lib4mode = 0) | (ppclibmode = 0) THEN; DO
  154.                 p5init         = 1
  155.                 romlibs        = 1
  156.                 ppccheck    = 1
  157.             END;
  158.         END; ELSE; DO
  159.             p5init        = 0
  160.             romlibs        = 0
  161.             ppccheck    = 0
  162.         END;
  163.  
  164.         IF p5init = 1 THEN;DO
  165.             rv=WRITELN(.out,"");
  166.             rv=WRITELN(.out,";P5 fixes follow here:");
  167.             rv=WRITELN(.out,";If you do not own a P5 board, you may remove the following lines");
  168.             rv=WRITELN(.out,";");
  169.             rv=WRITELN(.out,";Several P5 boards build a private MMU setup on boot");
  170.             rv=WRITELN(.out,";using a kludge called the BOOT-MMU-Port. To run this");
  171.             rv=WRITELN(.out,";kludge, the following external command is run from");
  172.             rv=WRITELN(.out,";LIBS:mmu/ as all other external commands");
  173.             rv=WRITELN(.out,";");
  174.             rv=WRITELN(.out,";This command installs also other P5 relevant MMU settings");
  175.             rv=WRITELN(.out,";Hence, for P5 boards, please keep it in place even if");
  176.             rv=WRITELN(.out,";you *DO NOT* see the BOOT-MMU-Port.");
  177.             rv=WRITELN(.out,";");
  178.             IF ~EXISTS("LIBS:mmu") THEN; DO
  179.                 OPTIONS FAILAT 15
  180.                 ADDRESS COMMAND 'MakeDir >NIL: LIBS:MMU'
  181.                 OPTIONS FAILAT 10
  182.             END;
  183.             IF ~EXISTS("LIBS:mmu/P5Init") THEN; DO
  184.                 ADDRESS COMMAND 'Copy >NIL: P5Init to LIBS:MMU/P5Init'
  185.             END;
  186.             rv=WRITELN(.out,"P5Init");
  187.             rv=WRITELN(.out,"");
  188.             rv=WRITELN(.out,"");
  189.         END;            
  190.  
  191.         IF ppccheck = 1 THEN; DO
  192.             ADDRESS COMMAND 'PPCIdentify'
  193.             ppccheck = RC;
  194.         END;
  195.  
  196.         IF ppccheck = 1 THEN; DO
  197.             SAY "The setup script found a P5 board with PPC processor.";
  198.             SAY "While not a problem in general, please note that you";
  199.             SAY "absolutely *MUST NOT* use the ppc.library together";
  200.             SAY "with the mmu.library. This won't work.";
  201.         END;
  202.  
  203.         IF romlibs = 1 THEN; DO
  204.             rv=WRITELN(.out,"");
  205.             rv=WRITELN(.out,";This board has some processor libs resident");
  206.             rv=WRITELN(.out,";BPPCFix should be run to remove it.");
  207.             rv=WRITELN(.out,";This command has been installed into C:");
  208.             rv=WRITELN(.out,";by the setup script.");
  209.             SAY "The setup script found some processor libraries resident in ROM";
  210.             SAY "You will not be able to use the MuLib specific processor";
  211.             SAY "libraries unless you run BPPCFix in your startup-sequence.";
  212.             SAY "Please study the BPPCFix manual for details on how to run";
  213.             SAY "this program to replace the ROM-based libraries."
  214.             SAY "";
  215.             SAY "Note further that you *DO NOT* need the ENVARC:MMU-Configuration"
  216.             SAY "file if you continue to use the ROM resident libraries.";
  217.             SAY "";
  218.             IF ~EXISTS("C:BPPCFix") THEN; DO
  219.                 ADDRESS COMMAND 'Copy >NIL: BPPCFix to C:BPPCFix'
  220.                 SAY "Copied BPPCFix to C: for convenience...";
  221.             END;
  222.         END;
  223.  
  224.         rv=WRITELN(.out,"");
  225.         rv=CLOSE(.out);
  226.         ADDRESS COMMAND 'Delete T:BoardInfo QUIET'
  227.     END    
  228.  
  229. RETURN 0
  230.  
  231.  
  232. ScanEntry:
  233. PARSE ARG base,end,mode
  234.  
  235.     base = X2D(SUBSTR(base,3,6))
  236.     end  = X2D(SUBSTR(end,3,6))+1
  237.  
  238.     copyback     =    INDEX(mode,'CopyBack')>0;
  239.     cacheinhibit    =    INDEX(mode,'CacheInhibit')>0;
  240.     invalid        =    INDEX(mode,'Blank')>0 | INDEX(mode,'Invalid')>0;
  241.     remapped    =    INDEX(mode,'Remapped')>0;
  242.     speedup        =    INDEX(mode,'NonSerial')>0 | INDEX(mode,'Imprecise')>0;
  243.     iomark        =    0;
  244.     board        =    0;
  245.  
  246.     DO i=1 TO boards
  247.         IF base<end.i & end>base.i THEN; DO
  248.             iomark = 1;    
  249.         END;
  250.     END;
  251.     
  252.     cachemodes    =    "WriteThrough";
  253.     iomodes        =    "";
  254.     IF copyback    THEN    cachemodes="CopyBack";
  255.     IF cacheinhibit    THEN    cachemodes="CacheInhibit";
  256.     IF speedup    THEN    cachemodes="CacheInhibit Imprecise NonSerial";
  257.     IF iomark    THEN    iomodes="IOSpace";
  258.  
  259.     memrange = "SetCacheMode 0x"D2X(base)"00 Size 0x"D2X(end-base)"00";
  260.  
  261.     zeropage    =    0;
  262.     chipmem        =    0;
  263.     zorro2        =    0;
  264.     iospace        =    0;
  265.     mother        =    0;
  266.     rangermem    =    0;
  267.     p5space        =    0;
  268.     ppcspace    =    0;
  269.     mem        =    0;
  270.     rom        =    0;
  271.  
  272.     IF end<=X2D('80')                 THEN zeropage    = 1;
  273.     IF end<=X2D('2000')                THEN chipmem    = 1;
  274.     IF base>=X2D('2000')    & end<=X2D('A000')    THEN zorro2    = 1;
  275.     IF base>=X2D('A000')    & end<=X2D('B800')    THEN iospace    = 1;
  276.     IF base>=X2D('B800')    & end<=X2D('C000')    THEN mother    = 1;
  277.     IF base>=X2D('C000')    & end<=X2D('D800')    THEN rangermem    = 1;
  278.     IF base>=X2D('DA00')    & end<=X2D('E000')    THEN mother    = 1;
  279.     IF base>=X2D('E800')    & end<=X2D('F000')    THEN iospace    = 1;
  280.     IF base>=X2D('F000')    & end<=X2D('F800')    THEN p5space    = 1;
  281.     IF base>=X2D('F800')    & end<=X2D('10000')    THEN rom    = 1;
  282.     IF base>=X2D('10000')    & end<=X2D('100000')    THEN mem    = 1;
  283.     IF base>=X2D('80000')    & end<=X2D('100000')    THEN ppcspace    = 1;
  284.     IF base>=X2D('100000')    & end<=X2D('800000')    THEN iospace    = 1;
  285.     IF base>=X2D('400000')    & end<=X2D('C00000')    THEN ppcspace    = 1;
  286.     IF base>=X2D('E00000')    & end<=X2D('1000000')    THEN p5space    = 1;
  287.     IF base>=X2D('FF0000')    & end<=X2D('FF1000')    THEN iospace    = 1;
  288.     IF iomark                    THEN iospace    = 1;
  289.     
  290.     /* found remapped chip memory */
  291.     IF zeropage & remapped THEN; DO
  292.         SAY 'Found a remapped ZeroPage, it might be a good idea to run MuFastZero.';
  293.         SAY 'If MuFastZero fails with "Zero page already remapped", please add the';
  294.         SAY 'FORCENATIVE command line option.';
  295.       END;
  296.  
  297.     /* found fast chip. This can be turned on in either case */
  298.     IF chipmem & (~remapped) & (~invalid) THEN; DO
  299.         rv=WRITELN(.out,";In case you don't run the V40 68040 resp. 68060.library");
  300.         rv=WRITELN(.out,";the following line will speed up the chip memory. It is");
  301.         rv=WRITELN(.out,";not required otherwise.");
  302.         rv=WRITELN(.out,memrange "CacheInhibit Imprecise NonSerial");
  303.                   rv=WRITELN(.out,"");
  304.     END;
  305.  
  306.     /* found slow zorro II or gfx mem? */
  307.     IF zorro2 & (~copyback) & (~invalid) & (~iomark) THEN; DO
  308.         rv=WRITELN(.out,";Found slow Zorro-II memory. Keeping the caches disabled.");
  309.         rv=WRITELN(.out,memrange "CacheInhibit Imprecise NonSerial Valid");
  310.         rv=WRITELN(.out,"");
  311.     END;
  312.  
  313.     /* copy attributes for the IO space */
  314.     IF iospace & (~invalid) & (~remapped) THEN; DO
  315.         rv=WRITELN(.out,memrange cachemodes "Valid IOSpace");
  316.         rv=WRITELN(.out,"");
  317.     END;
  318.  
  319.     /* setup ranger memory */
  320.     IF rangermem & (~invalid) & (~remapped) THEN; DO
  321.         rv=WRITELN(.out,memrange "CacheInhibit Imprecise NonSerial Valid");
  322.         rv=WRITELN(.out,"");
  323.     END;
  324.  
  325.     /* setup P5 uglyness */
  326.     IF p5space & (~invalid) & (~remapped) & (~iospace) THEN; DO
  327.         rv=WRITELN(.out,";The following memory region should be left blank");
  328.         rv=WRITELN(.out,";according to the CBM design rules. It isn't...");
  329.         rv=WRITELN(.out,memrange cachemodes "Valid IOSpace");
  330.         rv=WRITELN(.out,"");
  331.     END;
  332.  
  333.     /* found remapped ROM? */
  334.     IF rom & remapped THEN; DO
  335.         SAY 'Found a remapped ROM, running MuFastRom might be a good idea,';
  336.         SAY 'but make sure you disable other ROM remappers before trying';
  337.         SAY 'to use the MMU.library setup.';
  338.     END;
  339.  
  340.     /* strange caching modes in RAM? */
  341.     IF mem THEN; DO
  342.         IF ~copyback THEN; DO
  343.             IF ~portwarn THEN; DO
  344.                 SAY 'WARNING! Found non-copyback memory regions.';
  345.                 SAY 'This could mean that either the ppc.library is running';
  346.                 SAY 'or P5 I/O hardware is active.';
  347.                 SAY 'For the time being, I do nothing about it, but you should';
  348.                 SAY 'check the MMU-Configuration file manually and follow the';
  349.                 SAY 'notes in this file for further testing.';
  350.                 rv=WRITELN(.out,"WARNING! Found non-copyback memory regions.");
  351.                 rv=WRITELN(.out,"This could mean that either the ppc.library is running");
  352.                 rv=WRITELN(.out,"or P5 I/O hardware is active.");
  353.                 rv=WRITELN(.out,"For the time being, I do nothing about it, but you could");
  354.                 rv=WRITELN(.out,"try to remove the semi-colon for the following lines:");
  355.                 portwarn = 1;
  356.             END;
  357.             rv=WRITELN(.out,";"memrange cachemodes "Valid");
  358.         END;
  359.     END;
  360.  
  361.     /* PPC memory area marked as valid? */
  362.     IF ppcspace & (~invalid) & (~remapped) THEN; DO
  363.         IF ~ppcwarn THEN; DO
  364.             SAY 'WARNING! Found possible PPC memory regions.';
  365.             SAY 'DO NOT RUN THE ppc.library or you get problems.';
  366.             ppcwarn = 1;
  367.         END;
  368.         rv=WRITELN(.out,";If you don't own a PPC, you may remove the next line:");
  369.         rv=WRITELN(.out,memrange cachemodes iomodes "Valid");
  370.         rv=WRITELN(.out,"");
  371.     END;
  372.  
  373.  
  374. RETURN 0
  375.